package com.bee.gateway.common.vo;

import com.alibaba.fastjson.JSON;
import com.bee.gateway.common.domain.FilterDefinition;
import com.bee.gateway.common.domain.PredicateDefinition;
import com.bee.gateway.common.domain.RoutesDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @author Damin.yang
 * @date 2019/07/31 15:28
 */
@Data
@ApiModel
@Slf4j
public class RouteVO {

    @NotBlank(message = "路由id不能为空")
    @ApiModelProperty(value = "网关路由id")
    private String routeId;

    @NotBlank(message = "uri不能为空")
    @ApiModelProperty(value = "网关uri")
    private String uri;

    @ApiModelProperty(value = "网关过滤器信息")
    private List<FilterDefinition> filters;

    @NotEmpty(message = "网关断言不能为空")
    @ApiModelProperty(value = "网关断言")
    private List<PredicateDefinition> predicates;

    @ApiModelProperty(value = "排序")
    private Integer orders;

    @ApiModelProperty(value = "网关路由描述信息")
    private String description;

    public RoutesDO toDO() {
        RoutesDO routesDO = new RoutesDO();
        routesDO.setDescription(description);
        routesDO.setRouteId(routeId);
        routesDO.setUri(uri);
        routesDO.setOrders(orders);
        routesDO.setFilters(JSON.toJSONString(filters));
        routesDO.setPredicates(JSON.toJSONString(predicates));
        return routesDO;
    }
}
